package org.slsale.controller.user;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.slsale.pojo.user.User;
import org.slsale.service.user.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;



@Controller
public class UserController {
	
	private Logger logger = Logger.getLogger(UserController.class);
	
	@Resource
	private UserService userservice;
	
	@RequestMapping("/index.html")
	public String index(){
		logger.debug("UserController Welcome");
		return "index";
		
	}
	
	@RequestMapping(value="/login.html")
	public String login(){
		return "login";
	}
	@RequestMapping("/dologin.html")	
	public ModelAndView dologin(User user){
		logger.debug("dologin===>用户名"+user.getLoginCode()+"密码====>"+user.getPassword());
		try {
			user=userservice.getLoginUser(user);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return new ModelAndView("loginsuccess");
		
	}
	@RequestMapping("/exit.html")
	public String exit(){
		return "exit";
		
	}
	@RequestMapping("/register.html")
	public String register(){
		return "register";
		
	}
	@RequestMapping("/doregister.html")
     public ModelAndView doregister(User user){
		try {
			int f=userservice.addUser(user);
			if(f>0){
				user=userservice.getLoginUser(user);
				
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return new ModelAndView("registersuccess");
		
		
	}
}
